package ch.connection;

import ch.exception.MessageNotFoundException;
import ch.mailbox.Message;

/** Classe per il reperimento del messaggio tramite pop
 * 
 * @author Giovanni Franza - GPLv3 - 8/6/2011
 *
 */

public class Retr implements Control {

	@Override
	public Object verify( String data, Object obj ) {
		Message qtc;
		try {
			qtc = ((ch.mailbox.User)obj).getMessage( Integer.parseInt( data ) );
		} catch ( MessageNotFoundException e ){
			qtc = null;
		}
		return qtc;
	}
	public String getResponse( Object qtc ) {
		if( qtc == null ) {
			return null;
		}
		try {
			return "+OK " + new Integer( ((ch.mailbox.Message)qtc).getMessageContent().length()+3 ).toString() + " octets" + ((ch.mailbox.Message)qtc).getMessageContent()+"\n.\n";
		} catch( MessageNotFoundException  e ) {
			return null;
		}
	}
}
